/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managed;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import session.SearchBeanLocal;

/**
 *
 * @author antonio
 */
@ManagedBean(name = "searchController")
@RequestScoped  
public class SearchControllerBean {
    
    private String username;
    
    private String label;
    
    @EJB
    private SearchBeanLocal searchBean;

    /**
     * Creates a new instance of SearchControllerBean
     */
    public SearchControllerBean() {
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }
    
    public String search() throws UnsupportedEncodingException {
        System.out.println("SEARCH");
        if(! this.searchBean.search(this.username)){
            label = "username non trovato";
            return null;
        }
        return "modifyPlayer.xhtml?faces-redirect=true&player=" + URLEncoder.encode(this.username, "UTF-8");
    }
    
}
